package base.model;

import lombok.Data;
import org.apache.http.HttpStatus;

/**
 * @author : GuoFei
 * @date : 2018/12/22 10:03
 */
@Data
public class Result<T> {

    private boolean success;
    private int code;
    private String message;
    private T data;

    public static Result error(){
        return error("操作失败");
    }

    public static Result error(String message){
        return new Result(false, HttpStatus.SC_INTERNAL_SERVER_ERROR, message, null);
    }

    public static Result successForMessage(String message){
        return new Result(true, HttpStatus.SC_OK, message, null);
    }

    public static Result success(){
        return success("一切正常",null);
    }

    public static <T> Result success(T t){
        return success("一切正常", t);
    }

    public static <T> Result success(String message, T data){
        return new Result(true,HttpStatus.SC_OK,message,data);
    }

    public Result(boolean success, int code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
